All Questions
Tagged with testingunit-testing
481 questions
4votes
3answers
314views
Clearing static state before testing each method
My SUT class depends on external static state (which generally should be avoided, I know). How do I make sure my tests do not depend on their order of execution? I mean other by introducing some reset(...
0votes
0answers
70views
Is Spring Boot Unit Test Coverage with Integration tests only a bad practice?
I have recently come across a few codebases at work where the previous developers chose to reach the >80% coverage criteria by writing only integration tests with the @SpringBootTest annotation ...
3votes
2answers
210views
Ensuring unit test data stays accurate
Say I have a method that expects data to be in some form to perform accurately. In the actual service/application flow, that data is formed upstream in other methods or services. How can I ensure the ...
1vote
1answer
112views
NUnit testOf attribute usage
What are the use cases of TestOf? I'm new to NUnit testing and from what I have seen, most people don't use this attribute that much. From my experience, TestOf helped me to quickly identify what ...
2votes
1answer
267views
Unit testing a Web Worker in JavaScript/TypeScript - Best Practice
I got assigned with writing unit tests for a class that instantiate a Worker inside in it's constructor. The code looks simmilar to this, class SomeClass { private _worker: Worker; constructor(...
0votes
2answers
378views
Origins of Unit Testing in hardware?
According to the Wikipedia entry for Unit Testing, it is defined as a technique for testing components of a system in strict isolation from each other, and it is described as having been expressly ...
18votes
10answers
7kviews
Would a middle ground between unit and integration tests be optimal
I've read many posts about unit tests only testing one object/class and mocking of objects should only be for direct dependencies of the object under tests. The only other option discussed for ...
0votes
1answer
397views
How to avoid too much mocking in unit tests in a database-heavy method?
I have a service method, acceptOrDenyJoinRequest, which follows a fairly complex flow (as depicted in this diagram): In my unit tests, the implementation details of this method are heavily reflected. ...
1vote
1answer
344views
Should I skip unit tests if integration tests cover the same scenarios?
I have a service method called acceptOrDenyJoinRequest that follows a logic similar to this flowchart (green boxes are ignored in code, and the light gray box calls an external service). According to ...
0votes
3answers
387views
Reusing constants in tests vs "magic" values
I'm writing tests to check if validation rules are working for my CRUD app. I have constants defining stuff like max length of each String field. I'm unsure if within tests I should create test data ...
17votes
10answers
6kviews
Why is global state hard to test? Doesn't setting the global state at the beginning of each test solve the problem?
According to Why is Global State so Evil?, I know one of the disadvantages of "global state" is that it makes code "harder to test". I do not disagree with this, but what I don't ...
0votes
4answers
298views
TDD and code reusability
Let's say that I've been iterating over my feature A with TDD. After several red-green-refactor cycles, I ended up with a nicely polished implementation with a part of the SUT encapsulated into some ...
4votes
8answers
3kviews
Should I write and commit unit tests for minor changes and bug fixes?
For example, if the change is "return users' full names instead of just last names", is it worth it to add a test for it? Would it make the test suit fragmented and confusing? Context: My ...
2votes
1answer
753views
Approach to software testing with docker
When discussing the testing approach, we had disagreements. We develop software that we package into an image and distribute. We have two suggestions for testing: Build a separate image with a test ...
3votes
3answers
1kviews
TDD when removing long lived feature
Suppose I had some Manager class that I need to change in regards to existing functionality by removing code. The Manager always sends an initial message after a connection was established to do an ...